<?php


namespace Xiaoguai\DesignPattern\DP016;


class Originator
{
    /**
     * @var $state string
     */
    protected $state;

    /**
     * @param string $state
     */
    public function setState(string $state): void
    {
        $this->state = $state;
    }

    /**
     * @return string
     */
    public function getState(): string
    {
        return $this->state;
    }

    public function createMemento(): Memento
    {
        return new Memento($this->state);
    }

    public function restoreMemento(Memento $memento): void
    {
        $this->setState($memento->getState());
    }
}